<template>
    <a-card :bordered="false">

        <!-- 查询区域 -->
        <div class="table-page-search-wrapper">
            <a-form layout="inline" @keyup.enter.native="searchQuery">
                <a-row :gutter="24">
                    <a-col :md="6" :sm="24">
                        <a-form-item label="创建时间">
                            <a-range-picker
                                :placeholder="['开始时间', '结束时间']"
                                v-model="rangeTime"
                                format="YYYY-MM-DD"
                                @change="handleDateChange"
                            />
                        </a-form-item>
                    </a-col>
                    <a-col :span="6">
                        <a-form-item label="任务标题">
                            <a-input placeholder="请输入任务标题" v-model="queryParam.taskTitle"></a-input>
                        </a-form-item>
                    </a-col>
                    <a-col :span="6" >
                        <a-form-item label="任务类型">
                            <select-law-type :typesId="queryParam.typeId" @change="changeType" ></select-law-type>
                        </a-form-item>
                    </a-col>
                    <a-col :span="6">
                        <a-form-item label="任务状态">
                            <a-select placeholder="任务状态" v-model="queryParam.taskState">
                                <a-select-option value="">全部</a-select-option>
                                <a-select-option value="0">待发布</a-select-option>
                                <a-select-option value="1">已发布</a-select-option>
                                <a-select-option value="2">已撤回</a-select-option>
                                <a-select-option value="3">已完成</a-select-option>
                                <a-select-option value="4">已失效</a-select-option>
                            </a-select>
                        </a-form-item>
                    </a-col>

                    <a-col :span="8">
                        <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
                          <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
                          <a-button type="primary" @click="searchQuery" icon="search" style="margin-left: 8px">查询</a-button>
                          <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
                        </span>
                    </a-col>

                </a-row>
            </a-form>
        </div>

        <!-- 操作按钮区域 -->
        <div class="table-operator">

            <!--            <a-button type="primary" icon="download" @click="handleExportXls('系统通告')">导出</a-button>-->
            <!--            <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader"-->
            <!--                      :action="importExcelUrl" @change="handleImportExcel">-->
            <!--                <a-button type="primary" icon="import">导入</a-button>-->
            <!--            </a-upload>-->
            <a-dropdown v-if="selectedRowKeys.length > 0">
                <a-menu slot="overlay">
                    <a-menu-item key="1" @click="batchDel">
                        <a-icon type="delete"/>
                        删除
                    </a-menu-item>
                </a-menu>
                <a-button style="margin-left: 8px"> 批量操作
                    <a-icon type="down"/>
                </a-button>
            </a-dropdown>
        </div>

        <!-- table区域-begin -->
        <div>
            <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
                <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{
                    selectedRowKeys.length }}</a>项
                <a style="margin-left: 24px" @click="onClearSelected">清空</a>
            </div>

            <a-table
                ref="table"
                size="middle"
                bordered
                rowKey="id"
                :columns="columns"
                :dataSource="dataSource"
                :pagination="ipagination"
                :loading="loading"
                :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
                @change="handleTableChange">

               <span slot="action" slot-scope="text, record">
                   <a-popconfirm title="确定发布吗?" @confirm="() => releaseData(record.id)" v-if="record.taskState == 0">
                      <a>发布</a>
                    </a-popconfirm>
                   <a-divider type="vertical" v-if="record.taskState == 0"/>
                    <a @click="handleEdit(record)" v-if="record.taskState == 0">编辑</a>
                    <a-divider type="vertical" v-if="record.taskState == 0"/>
                   <a-popconfirm title="确定撤销吗?" @confirm="() => revocationData(record.id)" v-if="record.taskState == 1">
                      <a>撤销</a>
                    </a-popconfirm>
                   <a-divider type="vertical" v-if="record.taskState == 1"/>
                   <a @click="handleDetail(record)">详情</a>
                   <a-divider type="vertical" v-if="record.taskState == 2 || record.taskState == 3 || record.taskState == 4"/>
                   <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)" v-if="record.taskState == 2 || record.taskState == 3 || record.taskState == 4">
                      <a>删除</a>
                    </a-popconfirm>
                </span>
                <template slot="htmlSlot" slot-scope="text">
                    <div v-html="text"></div>
                </template>

            </a-table>
        </div>
        <!-- table区域-end -->

        <!-- 表单区域 -->
        <law-task-modal ref="modalForm" @ok="modalFormOk"></law-task-modal>
    </a-card>
</template>

<script>
import lawTaskModal from './lawTaskModal'
import { doReleaseData, doReovkeData } from '@api/api'
import { postAction } from '@api/manage'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import SelectLawType from '@comp/Jane/SelectLawType'
import { GET_USER_AUTH } from '@/utils/util'

export default {
    name: 'lawClauseList',
    mixins: [JeecgListMixin],
    components: {
        lawTaskModal,
        SelectLawType
    },
    data() {
        return {
            description: '执法任务管理页面',
            // 查询条件
            queryParam: {
                creatTimeBegin : null,
                creatTimeEnd : null,
            },
            rangeTime : [],
            // 表头
            columns: [
                {
                    title: '#',
                    dataIndex: '',
                    key: 'rowIndex',
                    width: 60,
                    align: 'center',
                    customRender: function(t, r, index) {
                        return parseInt(index) + 1
                    }
                },
                {
                    title: '任务类型',
                    align: 'center',
                    dataIndex: 'typeName'
                },
                {
                    title: '任务标题',
                    align: 'center',
                    dataIndex: 'taskTitle'
                },
                {
                    title: '任务时间段',
                    align: 'center',
                    dataIndex: 'timeline'
                },
                {
                    title: '任务状态',
                    align: 'center',
                    dataIndex: 'taskState',
                    customRender: function(t, r, index) {
                        if (r.taskState == 0) {
                            return '待发布';
                        } else if (r.taskState == 1) {
                            return '已发布';
                        }  else if (r.taskState == 2) {
                            return '已撤回';
                        }else if (r.taskState == 3) {
                            return '已完成';
                        }else if (r.taskState == 4) {
                            return '已失效';
                        }
                    },
                },
                {
                    title: '任务创建时间',
                    align: 'center',
                    dataIndex: 'createTime'
                },
                {
                    title: '操作',
                    dataIndex: 'action',
                    align: 'center',
                    scopedSlots: { customRender: 'action' }
                }
            ],
            url: {
                list: '/hc/hcLawEnforcementTask/WebPage',
                delete: '/hc/hcLawEnforcementTask/delete',
                deleteBatch: '/hc/hcLawEnforcementTask/deleteBatch',
                releaseDataUrl: '/hc/hcLawEnforcementTask/doReleaseData',
                reovkeDataUrl: 'sys/annountCement/doReovkeData',
                exportXlsUrl: 'sys/annountCement/exportXls',
                importExcelUrl: 'sys/annountCement/importExcel'
            }
        }
    },
    computed: {
        importExcelUrl: function() {
            return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
        }
    },
    methods: {
        //配置默认信息
         initConfig() {
            this.queryParam.creatTimeBegin = new Date().MonthFirstDay()
            this.queryParam.creatTimeEnd = new Date().MonthLastDay()
            this.rangeTime = [this.queryParam.creatTimeBegin, this.queryParam.creatTimeEnd]
            this.loadData(1)
        },
        // 初始化配置信息
        initDictConfig() {
            this.initConfig()
        },
        // 选择时间
        handleDateChange(value, dateString) {
            this.rangeTime = dateString
            if (dateString[0]) {
                this.queryParam.creatTimeBegin = dateString[0]
            }
            if (dateString[1]) {
                this.queryParam.creatTimeEnd = dateString[1]
            }
            this.loadData(1)
        },
        // 选择任务类型
        changeType(value) {
            this.queryParam.typeId = value;
            this.loadData(1)
        },
        //执行发布操作
        releaseData: function(id) {
            let that = this
            postAction('/hc/hcLawEnforcementTask/send',{ id: id ,taskState: 1 }).then((res) => {
                if (res.success) {
                    that.$message.success(res.message)
                    that.loadData(1)
                } else {
                    that.$message.warning(res.message)
                }
            })
        },

        //执行撤销操作
        revocationData: function(id) {
            let that = this
            postAction('/hc/hcLawEnforcementTask/send',{ id: id ,taskState: 2 }).then((res) => {
                if (res.success) {
                    that.$message.success(res.message)
                    that.loadData(1)
                } else {
                    that.$message.warning(res.message)
                }
            })
        },
    }
}
</script>
<style scoped>
@import '~@assets/less/common.less'
</style>
